package org.example;

public class Player {
    String name;
    int score;
    int life;
    //构造函数
    //构造函数的概念：当创建对象时，会自动调用构造函数，用于初始化对象的属性值
    public Player(String name) {
        this.name = name;
        score = 0;
        life = 3;
    }
    //玩家类的行为：输出游戏开始，增加分数
    public void startGame() {
        System.out.println("游戏开始！");
    }
    public void addScore(int score) {
        this.score += score;
    }
    public void showInfo() {
        System.out.println("玩家名：" + name + "，分数：" + score + "，生命值：" + life);
    }
}

